package cn.iocoder.yudao.module.dlbz.controller.admin.companyscoresendrecord;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.dlbz.controller.admin.companyscoresendrecord.vo.*;
import cn.iocoder.yudao.module.dlbz.dal.dataobject.companyscoresendrecord.CompanyScoreSendRecordDO;
import cn.iocoder.yudao.module.dlbz.service.companyscoresendrecord.CompanyScoreSendRecordService;

@Tag(name = "管理后台 - 企业积分发放记录")
@RestController
@RequestMapping("/dlbz/company-score-send-record")
@Validated
public class CompanyScoreSendRecordController {

    @Resource
    private CompanyScoreSendRecordService companyScoreSendRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建企业积分发放记录")
    @PreAuthorize("@ss.hasPermission('dlbz:company-score-send-record:create')")
    public CommonResult<Long> createCompanyScoreSendRecord(@Valid @RequestBody CompanyScoreSendRecordSaveReqVO createReqVO) {
        return success(companyScoreSendRecordService.createCompanyScoreSendRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新企业积分发放记录")
    @PreAuthorize("@ss.hasPermission('dlbz:company-score-send-record:update')")
    public CommonResult<Boolean> updateCompanyScoreSendRecord(@Valid @RequestBody CompanyScoreSendRecordSaveReqVO updateReqVO) {
        companyScoreSendRecordService.updateCompanyScoreSendRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除企业积分发放记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('dlbz:company-score-send-record:delete')")
    public CommonResult<Boolean> deleteCompanyScoreSendRecord(@RequestParam("id") Long id) {
        companyScoreSendRecordService.deleteCompanyScoreSendRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得企业积分发放记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('dlbz:company-score-send-record:query')")
    public CommonResult<CompanyScoreSendRecordRespVO> getCompanyScoreSendRecord(@RequestParam("id") Long id) {
        CompanyScoreSendRecordDO companyScoreSendRecord = companyScoreSendRecordService.getCompanyScoreSendRecord(id);
        return success(BeanUtils.toBean(companyScoreSendRecord, CompanyScoreSendRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得企业积分发放记录分页")
    @PreAuthorize("@ss.hasPermission('dlbz:company-score-send-record:query')")
    public CommonResult<PageResult<CompanyScoreSendRecordRespVO>> getCompanyScoreSendRecordPage(@Valid CompanyScoreSendRecordPageReqVO pageReqVO) {
        PageResult<CompanyScoreSendRecordDO> pageResult = companyScoreSendRecordService.getCompanyScoreSendRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CompanyScoreSendRecordRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出企业积分发放记录 Excel")
    @PreAuthorize("@ss.hasPermission('dlbz:company-score-send-record:export')")
    @OperateLog(type = EXPORT)
    public void exportCompanyScoreSendRecordExcel(@Valid CompanyScoreSendRecordPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<CompanyScoreSendRecordDO> list = companyScoreSendRecordService.getCompanyScoreSendRecordPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "企业积分发放记录.xls", "数据", CompanyScoreSendRecordRespVO.class,
                        BeanUtils.toBean(list, CompanyScoreSendRecordRespVO.class));
    }

}